﻿#pragma once

#include <memory>

#ifdef PLATFORM_WINDOWS
#ifdef BUILD_DLL
#define ENGINE_API __declspec(dllexport)
#else
		#define ENGINE_API __declspec(dllimport)
#endif // BUILD_DLL
#else
	#error 目前只支持Windows平台
#endif // PLATFORM_WINDOWS

#define ENGINE_TRACE(...)     Engine::LogSystem::GetEngineLogger()->trace(__VA_ARGS__);
#define ENGINE_INFO(...)      Engine::LogSystem::GetEngineLogger()->info(__VA_ARGS__);
#define ENGINE_WARN(...)      Engine::LogSystem::GetEngineLogger()->warn(__VA_ARGS__);
#define ENGINE_ERROR(...)     Engine::LogSystem::GetEngineLogger()->error(__VA_ARGS__);

#define LOG_TRACE(...)        Engine::LogSystem::GetEditorLogger()->trace(__VA_ARGS__);
#define LOG_INFO(...)         Engine::LogSystem::GetEditorLogger()->info(__VA_ARGS__);
#define LOG_WARN(...)         Engine::LogSystem::GetEditorLogger()->warn(__VA_ARGS__);
#define LOG_ERROR(...)        Engine::LogSystem::GetEditorLogger()->error(__VA_ARGS__);

#ifdef DEBUG
#define ASSERT(x, ...) {if(!(x)){LOG_ERROR("断言失败：{0}", __VA_ARGS__); __debugbreak();}}
#define ENGINE_ASSERT(x, ...) {if(!(x)){ENGINE_ERROR("断言失败：{0}", __VA_ARGS__); __debugbreak();}}
#else
	#define ASSERT(x, ...)
	#define ENGINE_ASSERT(x, ...)
#endif

#define BIND_EVENT_FUNCTION(FUNCTIONNAME) std::bind(&FUNCTIONNAME, this, std::placeholders::_1)

namespace Engine
{
	template <typename T>
	using Scope = std::unique_ptr<T>;

	template <typename T, typename... Args>
	constexpr Scope<T> CreateScope(Args&&... args)
	{
		return std::make_unique<T>(std::forward<Args>(args)...);
	}

	template <typename T>
	using Ref = std::shared_ptr<T>;

	template <typename T, typename... Args>
	constexpr Ref<T> CreateRef(Args&&... args)
	{
		return std::make_shared<T>(std::forward<Args>(args)...);
	}
}
